<?php
/**
 * Created by PhpStorm.
 * User: rhys
 * Date: 2018/3/26
 * Time: 下午7:26
 */

namespace App\Http\Controllers\H5\Shop;


use App\Common\Exceptions\AixinException;
use App\Common\Exceptions\AixinExceptionCode;
use App\Common\Service\CultivationService;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class CultivationController extends Controller
{
    /**
     * @var CultivationService
     */
    public $cultivationService;

    /**
     * CultivationController constructor.
     * @param $cultivationService
     */
    public function __construct(CultivationService $cultivationService)
    {
        $this->cultivationService = $cultivationService;
    }

    /**
     * @param Request $request
     * @return array
     * @throws AixinException
     */
    public function userCultivation(Request $request){
        $uid = $request->get('uid');
        $data = $this->cultivationService->getUserCultivation($uid);
        if (!$data){
            throw new AixinException(AixinExceptionCode::RESULT_NULL);
        }
        return ApiResponse($data);
    }

    public function userCultivationMore(Request $request)
    {
        $uid = $request->get('uid');
        $year = $request->get('year');
        $month = $request->get('month');
        $level = $request->get('level');
        $data = $this->cultivationService->getCultivationMore($uid,$year,$month,$level);
        if (empty($data)){
            throw new AixinException(AixinExceptionCode::RESULT_NULL);
        }
        return ApiResponse($data);
    }
}